import Cookies from 'js-cookie';

const tokenKey: string = "Admin-Token";

/**
 * 获取token信息
 * @returns 
 */
export const getToken = () => {
    const token = Cookies.get(tokenKey);
    // 如果token不存在，则移出本地缓存中的用户信息
    if(!token) {
        localStorage.removeItem("user");
    }
    return token;
}

/**
 * 设置token信息
 * @param token 
 */
export const setToken = (token: string) => {
    return Cookies.set(tokenKey, token);
}

/**
 * 移出token信息
 * @returns 
 */
export const removeToken = () => {
    localStorage.removeItem("user");
    return Cookies.remove(tokenKey);
}